/*
 * @Descripttion: 登录的一些逻辑方法
 * @Author: jhw
 * @Date: 2023-07-17 15:20:21
 * @LastEditors: jhw
 * @LastEditTime: 2023-07-17 17:31:07
 */

import { validateEmail, validatePassword, validateUsername, validateVarCode } from '@/utils/validate';
import { reactive } from 'vue';

//表单验证
export const useRules = () => {
  const loginRules = reactive({
    username: [{ validator: validateUsername, trigger: 'change' }],
    password: [{ validator: validatePassword, trigger: 'change' }],
  });
  // 注册表单校验规则
  const registerRules = reactive({
    username: [{ validator: validateUsername, trigger: 'change' }],
    email: [{ validator: validateEmail, trigger: 'change' }],
    password: [{ validator: validatePassword, trigger: 'change' }],
    verificationCode: [{ validator: validateVarCode, trigger: 'change' }],
  });

  const forgetRules = reactive({
    email: [{ validator: validateEmail, trigger: 'change' }],
    password: [{ validator: validatePassword, trigger: 'change' }],
    verificationCode: [{ validator: validateVarCode, trigger: 'change' }],
  });
  return {
    loginRules,
    registerRules,
    forgetRules,
  };
};
